class term {
  constructor(mongoose) {
    this.mongoose = mongoose
    this.Schema = mongoose.Schema
    // AnimeIntro模板
    this.termIntro = new this.Schema({

      userId: String,
      id: Number,
      name: String,
      content: String,
      scale: String,
      time: String,
      price: Number,
      min: Number,
      imgUrl: String,
      advice:String,

    })
    this.modal = this.mongoose.model('Term', this.termIntro)
  }

  // @paras1 查询条件 动漫名字数组
  // @paras2 查询结果过滤器
  // 返回查询结果
  termsFind(body) {
    return this.modal.find({userId:body.userId})
  }

  termFind(coachId) {
    // return this.modal.find().sort({ id: 1 }).skip(10 * body.page).limit(10)
    return this.modal.find({userId:coachId})

  }

  addTerm(body) {
    if (body.imgUrl === '') {
      let Term = new this.modal({
        userId: body.userId,
        id: body.id,
        name: body.name,
        content: body.content,
        scale: body.scale,
        time: body.time,
        price: body.price,
        min: body.min,
        imgUrl: '',
        advice:body.advice,
      })
      return Term.save()
    } else {
      return this.modal.updateOne({ id:body.id  }, { imgUrl: body.imgUrl })
    }

  }
}

module.exports = term
